<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Robot Control Panel</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f4f4f4;
        }
        .container {
            text-align: center;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: relative; /* 添加相对定位 */
        }
        button {
            padding: 10px 20px;
            margin: 5px;
            font-size: 16px;
            cursor: pointer;
        }
        p {
            font-size: 18px;
            margin-bottom: 20px;
        }
        .center-image {
            max-width: 17%;
            height: auto;
            display: block;
            margin: 20px auto; /* 居中显示 */
        }
        .settings-button {
            position: absolute; /* 绝对定位 */
            top: 10px; /* 距离顶部10px */
            right: 10px; /* 距离右侧10px */
            width: 50px; /* 按钮宽度 */
            height: 50px; /* 按钮高度 */
            border: none;
            border-radius: 50%; /* 使按钮为圆形 */
            background-color: #e0e0e0; /* 淡灰色背景 */
            color: #333; /* 文字颜色 */
            font-size: 24px;
            cursor: pointer;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        @media (max-width: 768px) {
            .container {
                width: 100%;
            }
            button {
                width: 80%; /* 占据屏幕宽度的80% */
            }
            .settings-button {
                top: 90px;
                right: 40px;
            }
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
    <div class="container">
        <h1>Robot Control Panel</h1>
        <p>Current Mode: <span id="current-mode">---</span></p>
        <img src="{{ url_for('static', filename='images/robot-logo.png') }}" alt="Robot Logo" class="center-image">
        <button onclick="changeMode('Standby')">Standby</button>
        <button onclick="changeMode('Forward')">Forward</button>
        <button onclick="changeMode('Run')">Run</button>
        <button onclick="changeMode('Backward')">Backward</button>
        <button onclick="changeMode('TurnLeft')">Turn Left</button>
        <button onclick="changeMode('TurnRight')">Turn Right</button>
        <button onclick="changeMode('ShiftLeft')">Shift Left</button>
        <button onclick="changeMode('ShiftRight')">Shift Right</button>
        <button onclick="changeMode('Climb')">Climb</button>
        <button onclick="changeMode('RotateX')">Rotate X</button>
        <button onclick="changeMode('RotateY')">Rotate Y</button>
        <button onclick="changeMode('RotateZ')">Rotate Z</button>
        <button onclick="changeMode('Twist')">Twist</button>

        <!-- 设置按钮 -->
        <button class="settings-button" onclick="goToSettings()">
            <i class="fas fa-cog"></i> <!-- 使用Font Awesome的齿轮图标 -->
        </button>
    </div>

    <script>
        function changeMode(mode) {
            fetch(`/api/remote/${mode}`, {
                method: 'GET',
            })
            .then(response => response.text())
            .then(data => {
                document.getElementById('current-mode').textContent = data;
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }

        function goToSettings() {
            window.location.href = '/servo-setting';
        }

        // 初始状态查询
        window.addEventListener('load', function() {
            fetch('/api/remote/getmode', {
                method: 'GET',
            })
            .then(response => response.text())
            .then(data => {
                document.getElementById('current-mode').textContent = data;
            })
            .catch(error => {
                console.error('Error:', error);
            });
        });
    </script>
</body>
</html>